//
//  SAStatisticsSummaryVC.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/7/23.
//

#import "SAStatisticsSummaryVC.h"
#import "SASpendingSummaryCell.h"
#import "HDDatePickerView.h"
#import "SAStatisticsExpendAppListAPI.h"
#import "SASearchStoreUserView.h"
#import "SAStatisticsTopUpModel.h"
#import "SAStatisticsManagementHeaderView.h"
#import "SAAddSpendingVC.h"

#import "saasRetail-Bridging-Header.h"
#import "DVPieChart.h"
#import "DVFoodPieModel.h"
#import "UILabel+NSMutableAttributedString.h"

#import "SASystemStoreStoreListAPI.h"
#import "SAStoreModel.h"
#import "BubbleTableView.h"

@interface SAStatisticsSummaryVC ()<UITableViewDelegate, UITableViewDataSource, HTTPAPIDelegate>

@property (nonatomic, strong) UIView *topContentView;
@property (nonatomic, strong) UILabel *startLab;
@property (nonatomic, strong) UILabel *startDateLab;
@property (nonatomic, strong) UILabel *endLab;
@property (nonatomic, strong) UILabel *endDateLab;
@property (nonatomic, strong) UIImageView *iconImageV;
@property (nonatomic, strong) UIButton *startDateBtn;
@property (nonatomic, strong) UIButton *endDateBtn;

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSDateFormatter *dateFormatter;
@property (nonatomic, strong) SAStatisticsExpendAppListAPI *statisticsExpendAppListAPI;
@property (nonatomic, strong) NSMutableArray *dataMarr;
@property (nonatomic, assign) NSInteger currentPage;
@property (nonatomic, strong) UILabel *totalLab;

@property (nonatomic, strong) UIView *tipView;
@property (nonatomic, strong) SAStoreUserModel *userModel;
@property (nonatomic, strong) DVPieChart *chart;
@property (nonatomic, strong) UIView *headerView;

@property (strong, nonatomic) PieChartView *pieChartView;
@property (nonatomic, strong) UILabel *allShopLab;
@property (nonatomic, strong) UIImageView *allowImageV2;

@property (nonatomic, strong) SASystemStoreStoreListAPI *systemStoreStoreListAPI;
@property (nonatomic, strong) NSMutableArray<SAStoreModel *> *storeList;
@property (nonatomic, strong) BubbleTableView *storeBubbleView;
@property (nonatomic, assign) NSInteger storeRow;


@end

@implementation SAStatisticsSummaryVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - HTTPAPIDelegate
- (void)fetchData:(id)data fromServerSuccessedWithAPI:(HTTPAPI *)api {
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
    if (self.statisticsExpendAppListAPI == api) {
        double totalAmount = [data[@"data"][@"totalAmount"] doubleValue] / 100;
        NSDictionary *expendDetailEntity = data[@"data"][@"expendDetailEntity"];
        NSDictionary *chartMap = data[@"data"][@"chartMap"];
        NSMutableArray *chartMarr = [NSMutableArray array];
        NSMutableArray *pieDataNameArray = [NSMutableArray array];
        __block double total = 0;
        [chartMap enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
            double value = [obj doubleValue]/ 100;
            if (value != 0) {
                total += value;
                [pieDataNameArray addObject:[NSString stringWithFormat:@"%@",key]];
                [chartMarr addObject:[NSString stringWithFormat:@"%0.2lf",value]];
            }
        }];
        
        //计算饼图,最小1%
        if (chartMarr.count > 0 && chartMarr.count < 6 && total > 0) {
            for (int i = 0; i < chartMarr.count; i++) {
                for (int j = i+1; j < chartMarr.count; j++) {
                    if ([chartMarr[i] doubleValue] > [chartMarr[j] doubleValue]) {
                        [pieDataNameArray exchangeObjectAtIndex:i withObjectAtIndex:j];
                        [chartMarr exchangeObjectAtIndex:i withObjectAtIndex:j];
                    }
                }
            }
            
            double rate1 = 0;
            double rate2 = 0;
            double rate3 = 0;
            double rate4 = 0;
            double rate5 = 0;
            
            for (int i = 0; i < chartMarr.count; i++) {
                double value = [chartMarr[i] doubleValue];
                double rate = roundf(value/total * 100)/100;
                if (rate < 0.005) {
                    rate = 0.005;
                }
                if (i == 0) {
                    rate1 = rate;
                }else if (i == 1) {
                    rate2 = rate;
                }else if (i == 2) {
                    rate3 = rate;
                }else if (i == 3) {
                    rate4 = rate;
                }else if (i == 4) {
                    rate5 = rate;
                }
            }
            
            if (chartMarr.count == 1){
                rate1 = 1;
            }else if (chartMarr.count == 2) {
                rate2 = 1 - rate1;
            }else if (chartMarr.count == 3) {
                rate3 = 1 - rate1 - rate2;
            }else if (chartMarr.count == 4) {
                rate4 = 1 - rate1 - rate2 - rate3;
            }else if (chartMarr.count == 5) {
                rate5 = 1 - rate1 - rate2 - rate3 - rate4;
            }
            
            NSMutableArray *dataArray = [NSMutableArray array];
            for (int i = 0; i < chartMarr.count; i++) {
                DVFoodPieModel *model1 = [[DVFoodPieModel alloc] init];
                double value = [chartMarr[i] doubleValue];
                model1.name = [NSString stringWithFormat:@"%@:%0.2f",pieDataNameArray[i],value];
                model1.value = value;
                if (i == 0) {
                    model1.rate = rate1;
                }else if (i == 1) {
                    model1.rate = rate2;
                }else if (i == 2) {
                    model1.rate = rate3;
                }else if (i == 3) {
                    model1.rate = rate4;
                }else if (i == 4) {
                    model1.rate = rate5;
                }
                [dataArray addObject:model1];
            }
            self.chart.dataArray = dataArray;
            [self.chart draw];
        }
        
        NSMutableArray *marr = [NSMutableArray array];
        NSMutableArray *marr2 = [NSMutableArray array];
        [expendDetailEntity enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
            double value = [obj doubleValue]/ 100;
            if (value != 0) {
                NSDictionary *dic = @{key:[NSString stringWithFormat:@"%0.2lf",value]};
                [marr addObject:dic];
                [marr2 addObject:[NSString stringWithFormat:@"%0.2lf",value]];
            }
        }];
        
        for (int i = 0; i < marr.count; i++) {
            for (int j = i+1; j < marr.count; j++) {
                if ([marr2[i] doubleValue] < [marr2[j] doubleValue]) {
                    [marr exchangeObjectAtIndex:i withObjectAtIndex:j];
                    [marr2 exchangeObjectAtIndex:i withObjectAtIndex:j];
                }
            }
        }
        
        self.dataMarr = marr;
        [self.tableView reloadData];
        
        _totalLab.text = [NSString stringWithFormat:@"合计支出  %0.2lf",totalAmount];
        [_totalLab setAttributedStringWithSubString:@"合计支出" color:kBlackColor];
        self.tipView.hidden = (chartMarr.count > 0);
    }else if (self.systemStoreStoreListAPI == api) {
        self.storeList = [SAStoreModel mj_objectArrayWithKeyValuesArray:data[@"data"]];
        for (NSInteger i = 0; i < self.storeList.count; i++) {
            if ([SAValueManger shareInStance].userInfo.merchantId == self.storeList[i].merchantId) {
                self.storeRow = i;
            }
        }
        [self showStoreList];
    }
}

- (void)fetchDataFromServerFailedWithError:(NSError *)error API:(HTTPAPI *)api {
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
}


#pragma mark - UITableView Delegate & DataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataMarr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SASpendingSummaryCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SASpendingSummaryCell" forIndexPath:indexPath];
    cell.dic = self.dataMarr[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kScaleNum(40.5);
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return kScaleNum(0.01);
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return kScaleNum(0.01);
}

#pragma mark - event
-(void)clickedAllowBtn2 {
    NSMutableArray *menuList = [SAValueManger shareInStance].userInfo.menuList;
    NSString *crossStoreSummary = [NSString stringWithFormat:@"%@",menuList[8][@"perms"][@"crossStoreSummary"]];
    if ([crossStoreSummary isEqualToString:@"1"]) {
        [Prompt popPromptViewWithMsg:@"您没有跨店查统计权限,请联系店长添加" duration:2];
        return;
    }
    
    if (self.storeList.count > 0) {
        [self showStoreList];
    }else {
        self.systemStoreStoreListAPI.returnAll = @"true";
        [self.systemStoreStoreListAPI sendRequestToServerWithActivityViewAndMask:GET];
    }
}
    
-(void)showStoreList{
    NSMutableArray *marr = [NSMutableArray array];
    for (SAStoreModel *model in self.storeList) {
        if (model.storeName.length == 0) {
            model.storeName = @"";
        }
        [marr addObject:model.storeName];
    }
    NSInteger height = marr.count * 50 + 10;
    if (height > 190) {
        height = 190;
    }
    NSArray *arr = nil;
    UIView *window = [UIApplication sharedApplication].keyWindow;
    if (!self.storeBubbleView) {
        self.storeBubbleView = [[BubbleTableView alloc] initWithLocation:(BubbleLocationDown) bubbleAlignment:(BubbleAlignmentRight) width:120 height:height cellClickBlock:^(NSInteger row, NSString * _Nonnull rowString, NSArray *fromDataArray) {
            self.storeRow = row;
            self.statisticsExpendAppListAPI.merchantId = @(self.storeList[row].merchantId).stringValue;
            self.allShopLab.text = rowString;
            self.currentPage = 1;
            [self loadData];
        } hideBlock:^{
            self.storeBubbleView = nil;
        }];
        [self.storeBubbleView showWithTargetView:self.allowImageV2 maskSuperView:window];
        [self.storeBubbleView updateBubble:marr fromDataArray:arr];// 更新气泡弹框
        self.storeBubbleView.bubbleCellHeight = 50;
        self.storeBubbleView.selectRow = self.storeRow;
        self.storeBubbleView.isBubbleScrollEnabled = YES;
        self.storeBubbleView.bubbleCellTextAlignment = NSTextAlignmentCenter;
    }
}

#pragma mark - initUI
-(void)initUI {
    [self setNavigationItemBackBBIAndTitle:@"支出汇总"];
    [self setBgImage:nil];
    self.view.backgroundColor = kBgColor;
    self.currentPage = 1;
    
    UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    searchBtn.frame = CGRectMake(0, 0, kScaleNum(60), kScaleNum(44));
    [searchBtn setImage:[UIImage imageNamed:@"white_add"] forState:UIControlStateNormal];
    [searchBtn addTarget:self action:@selector(clickedSearchBtn) forControlEvents:UIControlEventTouchUpInside];
    [self addRightViews:@[searchBtn]];
    
    [self.view addSubview:self.topContentView];
    [self.topContentView addSubview:self.startLab];
    [self.topContentView addSubview:self.startDateLab];
    [self.topContentView addSubview:self.endLab];
    [self.topContentView addSubview:self.endDateLab];
    [self.topContentView addSubview:self.iconImageV];
    [self.topContentView addSubview:self.startDateBtn];
    [self.topContentView addSubview:self.endDateBtn];
    
    [self.topContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(kScaleNum(StatusHeight));
        make.height.mas_equalTo(kScaleNum(50));
        make.right.mas_equalTo(0);
        make.left.mas_equalTo(kScaleNum(0));
    }];
    
    [self.iconImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(29, 29));
    }];
    
    [self.startLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.startDateLab);
        make.top.mas_equalTo(kScaleNum(3));
        make.height.mas_equalTo(kScaleNum(20));
    }];
    
    [self.startDateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.iconImageV.mas_left).offset(kScaleNum(-68));
        make.top.mas_equalTo(kScaleNum(27));
        make.height.mas_equalTo(kScaleNum(20));
    }];
    
    [self.endLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.endDateLab);
        make.top.mas_equalTo(kScaleNum(3));
        make.height.mas_equalTo(kScaleNum(20));
    }];
    
    [self.endDateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageV.mas_right).offset(kScaleNum(68));
        make.top.mas_equalTo(kScaleNum(27));
        make.height.mas_equalTo(kScaleNum(20));
    }];
    
    [self.startDateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.startDateLab);
        make.top.bottom.mas_equalTo(0);
    }];
    
    [self.endDateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.endDateLab);
        make.top.bottom.mas_equalTo(0);
    }];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *timeFormatStr = [dateFormatter stringFromDate:[NSDate date]];
    _startDateLab.text = timeFormatStr;
    _endDateLab.text = timeFormatStr;
    
    UIView *grayView = [[UIView alloc] initWithFrame:SARectMake(0, StatusHeight + 50, kBaseScreenWidth, 35)];
    grayView.backgroundColor = kBgColor;
    [self.view addSubview:grayView];
    
    UILabel *allShopLab = [[UILabel alloc] init];
    allShopLab.text = [SAValueManger shareInStance].userInfo.storeName;
    allShopLab.font = kBFont(15);
    allShopLab.textColor = kBlackColor;
    [grayView addSubview:allShopLab];
    self.allShopLab = allShopLab;
    
    UIImageView *allowImageV2 = [[UIImageView alloc] init];
    allowImageV2.image = [UIImage imageNamed:@"bule_downAllow"];
    [grayView addSubview:allowImageV2];
    allowImageV2.contentMode = UIViewContentModeCenter;
    self.allowImageV2 = allowImageV2;
    
    UIButton *allowBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [allowBtn2 addTarget:self action:@selector(clickedAllowBtn2) forControlEvents:UIControlEventTouchUpInside];
    [grayView addSubview:allowBtn2];
    
    [allShopLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(kScaleNum(25));
        make.height.mas_equalTo(kScaleNum(35));
        make.width.mas_lessThanOrEqualTo(kScaleNum(150));
        make.width.mas_greaterThanOrEqualTo(kScaleNum(50));
    }];
    
    [allowImageV2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(kScaleNum(35));
        make.width.mas_equalTo(kScaleNum(55));
        make.left.mas_equalTo(allShopLab.mas_right).offset(kScaleNum(-10));
    }];
    
    [allowBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(0);
        make.height.mas_equalTo(kScaleNum(35));
        make.right.mas_equalTo(allShopLab.mas_right).offset(kScaleNum(30));
    }];
    
    [self.view addSubview:self.tableView];
    
    UIView *headerView = [[UIView alloc] initWithFrame:SARectMake(0, 0, kBaseScreenWidth, 300)];
    headerView.backgroundColor = [UIColor whiteColor];
    self.tableView.tableHeaderView = headerView;
    self.headerView = headerView;
    
    self.statisticsExpendAppListAPI.currentPage = 1;
    self.statisticsExpendAppListAPI.pageSize = 10000;
    self.statisticsExpendAppListAPI.startTime = timeFormatStr;
    self.statisticsExpendAppListAPI.endTime = timeFormatStr;
    self.statisticsExpendAppListAPI.closing = @"0";
    self.statisticsExpendAppListAPI.merchantId = @([SAValueManger shareInStance].userInfo.merchantId).stringValue;
    [self.statisticsExpendAppListAPI sendRequestToServerWithActivityViewAndMask:POST];
    
    UILabel *totalLab = [[UILabel alloc] initWithFrame:SARectMake(0, 0, kBaseScreenWidth - 30, 40)];
    totalLab.text = @"合计支出";
    totalLab.font = kFont(15);
    totalLab.textColor = kPinkColor;
    totalLab.textAlignment = NSTextAlignmentRight;
    [headerView addSubview:totalLab];
    self.totalLab = totalLab;
    
    DVPieChart *chart = [[DVPieChart alloc] initWithFrame:CGRectMake(0, kScaleNum(40), kScreenWidth, kScaleNum(250))];
    self.chart = chart;
    chart.title = @"支出";
    chart.backgroundColor = [UIColor whiteColor];
    [self.headerView addSubview:chart];
    
    UIView *line = [[UIView alloc] initWithFrame:SARectMake(0, 295, kBaseScreenWidth, 5)];
    line.backgroundColor = kBgColor;
    [self.headerView addSubview:line];
    
    [self.view addSubview:self.tipView];
}

-(void)clickedSearchBtn {
    SAAddSpendingVC *pushVC = [SAAddSpendingVC new];
    [self.navigationController pushViewController:pushVC animated:YES];
    WeakSelf
    pushVC.refreshBlock = ^{
        [weakSelf loadData];
    };
}

- (void)clickStartDateBtn:(UIButton *)btn {
    WeakSelf
    HDDatePickerView *pickerView = [[HDDatePickerView alloc] initWithSlectedDate:self.startDateLab.text];
    [pickerView show];
    pickerView.selectDateBlock = ^(NSString *selectedDate) {
        NSDate *date1 = [self.dateFormatter dateFromString:selectedDate];
        NSDate *date2 = [self.dateFormatter dateFromString:weakSelf.endDateLab.text];
        if ([date1 compare:date2] == NSOrderedDescending) {
            [Prompt popPromptViewWithMsg:@"开始日期不能大于截止日期" duration:2];
        }else {
            weakSelf.startDateLab.text = selectedDate;
            weakSelf.currentPage = 1;
            weakSelf.statisticsExpendAppListAPI.startTime = selectedDate;
            [weakSelf loadData];
        }
    };
}

- (void)clickEndDateBtn:(UIButton *)btn {
    WeakSelf
    HDDatePickerView *pickerView = [[HDDatePickerView alloc] initWithSlectedDate:self.endDateLab.text];
    [pickerView show];
    pickerView.selectDateBlock = ^(NSString *selectedDate) {
        NSDate *date1 = [self.dateFormatter dateFromString:selectedDate];
        NSDate *date2 = [self.dateFormatter dateFromString:weakSelf.startDateLab.text];
        if ([date1 compare:date2] == NSOrderedAscending) {
            [Prompt popPromptViewWithMsg:@"截止日期不能小于开始日期" duration:2];
        }else {
            weakSelf.endDateLab.text = selectedDate;
            weakSelf.currentPage = 1;
            weakSelf.statisticsExpendAppListAPI.endTime = selectedDate;
            [weakSelf loadData];
        }
    };
}

-(void)loadData {
    self.statisticsExpendAppListAPI.currentPage = 1;
    [self.statisticsExpendAppListAPI sendRequestToServerWithActivityViewAndMask:POST];
}

#pragma mark - lazy
- (UIView *)topContentView {
    if (!_topContentView) {
        _topContentView = [[UIView alloc] init];
        _topContentView.backgroundColor = [UIColor whiteColor];
    }
    return _topContentView;
}

- (UILabel *)startLab {
    if (!_startLab) {
        _startLab = [[UILabel alloc] init];
        _startLab.textColor = kBlackColor;
        _startLab.font = kFont(15);
        _startLab.text = @"开始";
    }
    return _startLab;
}

- (UILabel *)startDateLab {
    if (!_startDateLab) {
        _startDateLab = [[UILabel alloc] init];
        _startDateLab.textColor = kBlackColor;
        _startDateLab.font = kFont(15);
    }
    return _startDateLab;
}

- (UILabel *)endLab {
    if (!_endLab) {
        _endLab = [[UILabel alloc] init];
        _endLab.textColor = kBlackColor;
        _endLab.font = kFont(15);
        _endLab.text = @"截止";
    }
    return _endLab;
}

- (UILabel *)endDateLab {
    if (!_endDateLab) {
        _endDateLab = [[UILabel alloc] init];
        _endDateLab.textColor = kBlackColor;
        _endDateLab.font = kFont(15);
    }
    return _endDateLab;
}

- (UIImageView *)iconImageV {
    if (!_iconImageV) {
        _iconImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SA_to"]];
    }
    return _iconImageV;
}

- (UIButton *)startDateBtn {
    if (!_startDateBtn) {
        _startDateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_startDateBtn addTarget:self action:@selector(clickStartDateBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _startDateBtn;
}

- (UIButton *)endDateBtn {
    if (!_endDateBtn) {
        _endDateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_endDateBtn addTarget:self action:@selector(clickEndDateBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _endDateBtn;
}

-(UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kScaleNum(StatusHeight + 85), kScreenWidth, kScreenHeight - kScaleNum(StatusHeight + 85)) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = kBgColor;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsHorizontalScrollIndicator = NO;
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        [_tableView registerClass:[SASpendingSummaryCell class] forCellReuseIdentifier:@"SASpendingSummaryCell"];
    }
    return _tableView;
}

-(UIView *)tipView {
    if (!_tipView) {
        _tipView = [[UIView alloc] initWithFrame:CGRectMake(0, kScaleNum(StatusHeight + 85), kScreenWidth, kScreenHeight - kScaleNum(StatusHeight + 85))];
        _tipView.backgroundColor = [UIColor whiteColor];
        UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Shop_search2"]];
        icon.frame = SARectMake(124, 106, 138, 83);
        [_tipView addSubview:icon];
        UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, icon.maxY + kScaleNum(20), _tipView.width, kScaleNum(20))];
        titleLab.text = @"暂无相关信息";
        titleLab.textAlignment = NSTextAlignmentCenter;
        titleLab.textColor = kGrayColor;
        [_tipView addSubview:titleLab];
    }
    return _tipView;
}

-(NSDateFormatter *)dateFormatter {
    if (!_dateFormatter) {
        _dateFormatter = [NSDateFormatter new];
        [_dateFormatter setDateFormat:@"yyyy-MM-dd"];
    }
    return _dateFormatter;
}

-(SAStatisticsExpendAppListAPI *)statisticsExpendAppListAPI {
    if (!_statisticsExpendAppListAPI) {
        _statisticsExpendAppListAPI = [SAStatisticsExpendAppListAPI apiWithDelegate:self];
    }
    return _statisticsExpendAppListAPI;
}

-(NSMutableArray *)dataMarr {
    if (!_dataMarr) {
        _dataMarr = [NSMutableArray array];
    }
    return _dataMarr;
}

-(SASystemStoreStoreListAPI *)systemStoreStoreListAPI {
    if (!_systemStoreStoreListAPI) {
        _systemStoreStoreListAPI = [SASystemStoreStoreListAPI apiWithDelegate:self];
    }
    return _systemStoreStoreListAPI;
}

-(NSMutableArray<SAStoreModel *> *)storeList {
    if (!_storeList) {
        _storeList = [NSMutableArray array];
    }
    return _storeList;
}

@end
